﻿using System.IO;
using System.Linq;

namespace RaytracerLib
{
    public static class PathResolver
    {
        public static DirectoryInfo TexturesDir
        {
            get
            {
                return new DirectoryInfo(BaseDir() +
                    Path.DirectorySeparatorChar + "Raytracer" + Path.DirectorySeparatorChar +
                    "Textures");
            }
        }

        public static DirectoryInfo TestScenesDir
        {
            get
            {
                return new DirectoryInfo(BaseDir() +
                    Path.DirectorySeparatorChar + "RaytracerTest" + Path.DirectorySeparatorChar +
                    "TestScenes");
            }
        }

        private static string BaseDir()
        {
            var di = new DirectoryInfo(System.Reflection.Assembly.GetAssembly(
                typeof(PathResolver)).Location).Parent;

            for (; ; )
            {
                if (di.EnumerateFiles().Any(f => f.Name == "Raytracer.sln"))
                    return di.FullName;
                di = di.Parent;
            }
        }

        public static string GetTexturePath(string a_fileName)
        {
            return TexturesDir.FullName + Path.DirectorySeparatorChar + a_fileName;
        }
    }
}